<?php

use yii\helpers\Url;

?>

<div class="layui-fluid">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-header">设置我的资料</div>
                <div class="layui-card-body" pad15>

                    <div class="layui-form" lay-filter="">
                        <div class="layui-form-item">
                            <label class="layui-form-label">我的角色</label>
                            <div class="layui-input-inline">
                                <input type="text" name="" value="<?=$user->role['name']?>" readonly class="layui-input">
                                <input type="hidden" name="role_id" value="<?=$user->role_id?>">
                                <input type="hidden" name="id" value="<?=$user->id?>">
                                <input type="hidden" name="<?=Yii::$app->request->csrfParam?>" value="<?=Yii::$app->request->csrfToken?>">
                            </div>
                            <div class="layui-form-mid layui-word-aux">当前角色不可更改为其它角色</div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">用户名</label>
                            <div class="layui-input-inline">
                                <input type="text" name="name" value="<?=$user->name?>" readonly class="layui-input">
                            </div>
                            <div class="layui-form-mid layui-word-aux">不可修改。一般用于后台登入名</div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">密码</label>
                            <div class="layui-input-inline">
                                <input type="password" name="password" value="" lay-verify="nickname" autocomplete="off"
                                       placeholder="不修改则不填写" class="layui-input">
                                <span class="x-red">不修改则不填写</span>
                            </div>
                        </div>

                        <div class="layui-form-item">
                            <div class="layui-input-block">
                                <button class="layui-btn" lay-submit lay-filter="userEdit">确认修改</button>
                            </div>
                        </div>
                    </div>

                </div>
            </div>
        </div>
    </div>
</div>
<?php $this->beginBlock('footer')?>
<script>
    layui.use('form',function () {
        var form = layui.form;
        form.on('submit(userEdit)',function (data) {
            let field = data.field;
            if(!field.password){
                layer.msg('你尚未填写密码！');return;
            }
            $.post('<?=Url::toRoute(['index/user'])?>',field,function (res) {
                if(res.status==200){
                    layer.msg(res.msg,{icon:6,time:1500},function () {
                        location.reload();
                    })
                }else {
                    layer.msg(res.msg,{icon:5,time:1000})
                }
            },'json')
        })
    })
</script>
<?php $this->endBlock()?>
